﻿Module RoleDao

    Public Sub insert(ByVal id As Integer, ByVal name As String, ByVal description As String)
        DataAccessConnection.openConnection()

        Dim command As New Data.OleDb.OleDbCommand

        Dim query As String = ""
        query = "INSERT INTO ROLE (name, description) "
        query &= "values('" & name & "', '" & description & "')"

        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = query

        command.ExecuteNonQuery()


        DataAccessConnection.closeConnection()

    End Sub

    Public Sub update(ByVal id As Integer, ByVal name As String, ByVal description As String)
        DataAccessConnection.openConnection()
        Dim command As New Data.OleDb.OleDbCommand

        Dim query As String = ""

        query = "UPDATE ROLE"
        query &= "SET description = '" & description & "' , "
        query &= " WHERE id = " & id & ""

        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = query


        command.ExecuteNonQuery()

        DataAccessConnection.closeConnection()

    End Sub

    Public Function searchDataByFilter(ByVal stringTable As String, ByVal id As Integer, ByVal name As String)
        DataAccessConnection.openConnection()

        Dim command As New Data.OleDb.OleDbCommand
        Dim table As New Data.DataTable

        Dim query As String = ""

        query = "SELECT * FROM ROLE WHERE "
        query &= " name like ""%" & name & "%"""
        query &= " AND (id = " & id & " OR " & id & " = 0)"

        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = query

        table.Load(command.ExecuteReader)

        DataAccessConnection.closeConnection()

        Return table
    End Function

End Module
